package hzh;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.sql.SQLException;

public class UpdateServlet extends HttpServlet {

    private static final long serialVersionUID = 119833388866686380L;
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
        this.doPost(request, response);
    }
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
        request.setCharacterEncoding("UTF-8");
        String id       = request.getParameter("id");
        String name     = request.getParameter("name");
        String actors   = request.getParameter("actors");
        String type     = request.getParameter("type");
        String score    =request.getParameter("score");
        String price    = request.getParameter("price");
        String describe = request.getParameter("des");
        String pic =request.getParameter("pic");

        String sql = String.format("UPDATE `movies` SET " +
                        "`name`=\"%s\", `actors`=\"%s\", `score`=%s, `price`=%s, `type`=\"%s\", `des`=\"%s\"  " +
                        "WHERE `id`=%s",
                name, actors, score,price, type, describe, id
        );
        System.out.println(sql);
        try {
            DBUtils.update(sql);
            response.sendRedirect("./list1.jsp");
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
